﻿using MediatR;
using T_vehicle.API.Application.Command.RepairRecordsCommand;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.RepairRecordsCommandHandlers
{
    public class PDelRepairRecordsCommandHandlers : IRequestHandler<PDelRepairRecordsCommand, int>
    {
        private readonly IRepairRepository repairRepository;

        public PDelRepairRecordsCommandHandlers(IRepairRepository repairRepository)
        {
            this.repairRepository = repairRepository;
        }

        public async Task<int> Handle(PDelRepairRecordsCommand request, CancellationToken cancellationToken)
        {
            var Id = request.RepairRecordsId.Split(',').Select(x => Convert.ToInt32(x));
            var list = await repairRepository.GetAsync(x => Id.Contains(x.RepairRecordsId));
            foreach (var item in list)
            {
               item.IsDel = true;
            }
            return await repairRepository.UpdateAsyncRange(list);
        }
    }
}
